class WelcomeController < ApplicationController
  before_action :prepare

  #http://192.168.2.61:3001?code=212121211&send_user_nick=dsadada&send_msg=dadadasda&expire_time=2015.2.14_21:31&goods_id=10216&goods_title=dasdasdas&seller_id=127
  def index
    @code = []
    code_arr = params[:code].to_s.chars
    code_arr.each_with_index do |num, i|
      @code << num
      if (i+1) % 4 == 0
        @code << "  "
      end
    end
    @code = @code.join
    @send_user_nick = params[:send_user_nick] 
    @send_msg = params[:send_msg] 
    @expire_time = params[:expire_time] 
    @goods_id = params[:goods_id] 
    @goods_title = params[:goods_title] 
    @seller_id = params[:seller_id] 

    goods_info = @api.goodsInfo(@goods_id)

    @pic = "#{APIManager::IMAGE_BASE_PATH}#{goods_info["thumb_pic"]}"
    @goods_title = goods_info["title"]
    
  end

  def show
    @goods = @api.goodsInfo(params[:id])
    @sellerAll = @api.sellerInfo(@goods["seller_id"])

    @seller = @sellerAll["Info"]
    @stores = @sellerAll["StoreList"].to_a
  end

  private
  def prepare
    @api = APIManager.new
  end
 
end
